#include "myShaderGouraud.h"

myShaderGouraud::myShaderGouraud(){
	VSres = new Gouraud::VSR;
	PSres = new Gouraud::PSR;
	VS = Gouraud::VertexShader;
	PS = Gouraud::PixelShader;
	nSem = Gouraud::nSem;
	Sem	 = (InterpSemantic *)malloc (sizeof(Gouraud::Sem));
	*Sem = Gouraud::Sem[1];
	PSstride = sizeof(Gouraud::PIXELin);
}
myShaderGouraud::~myShaderGouraud(){
	delete (Gouraud::VSR*)VSres;
	delete (Gouraud::PSR*)PSres;
}
void myShaderGouraud::Update(void){
			Check();
		camera.Update();
			
			_mat4 matInv;
			_vec3 pos;
			_vec3 tmp;
			int test;
		
			int i = 0;
			int j = 0;

			
			matInv.set(world);
			matInv.inverse(matInv);
			
			((Gouraud::VSR*)VSres)->MFull.mul(camera.GetProjViewMatrix(),world);

			((Gouraud::VSR*)VSres)->ObsPos.mul(matInv,camera.GetPosition());
			((Gouraud::VSR*)VSres)->material = material;

			for(i=0;i<MaxLight;i++){
				if(lights[i].active){
					tmp = lights[i].pos;
					pos.mul(matInv,tmp);
					
					((Gouraud::VSR*)VSres)->lights[j].pos = pos;
					((Gouraud::VSR*)PSres)->lights[j].col = lights[i].col;	
					j++;
				}
			}	
			((Gouraud::VSR*)VSres)->nlights = j;
}